package com.team.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.team.entity.Record;
import com.team.util.DbHelp;
import com.team.util.ResultSetPackge;

public class RecordDao {
	
	DbHelp<Record> db = new DbHelp<Record>();

	public int saveRecord(Record record){
		String sql = "insert into t_record(content,createtime,t_contact_id,t_user_id )values(?,?,?,?)";
		return db.executeUpdateSql(sql, record.getContent(),record.getCreateTime(),record.getContactId(),record.getUserId());
		
	}
	
	
	public List<Record> selectByRecordId(int recordId){
		String sql = "select id,content,createtime,t_contact_id,t_user_id from t_record where t_contact_id= ? ";
		return db.exeSelectForList(sql, new PackgeRecord(), recordId);
		
	}
	

 private class PackgeRecord implements ResultSetPackge<Record>{

	public Record packgeResultSet(ResultSet rs) throws SQLException {
			Record record = new Record();
			record.setContactId(rs.getInt("t_contact_id"));
			record.setContent(rs.getString("content"));
			record.setCreateTime(rs.getString("createtime"));
			record.setId(rs.getInt("id"));
			record.setUserId(rs.getInt("t_user_id"));
			return record;
	}
		
	}
	  
}


